home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / datlnk.zip / DATELINK.PAS < prev    next >
Pascal/Delphi Source File  |  1993-01-04  |  5KB  |  174 lines

  1. {.I DMINUS.INC}
  2. {$O+} {so we can overlay this unit if we decide to}
  3.  
  4. UNIT DateLink;
  5.  
  6. INTERFACE {section}
  7.  
  8. USES
  9.    TpDate,
  10.    Objects,
  11.    ObjectA,
  12.    DateObj;
  13.  
  14. TYPE
  15.    DateLinkList
  16.     = OBJECT(LinkList)
  17.       CurrentDatePtr : DateObjectPtr;
  18.  
  19.       CONSTRUCTOR Init;
  20.       PROCEDURE   AddDate(TheDate : Date);
  21.       PROCEDURE   DeleteDate(TheDate : Date);
  22.       FUNCTION    Exists(TheDate : Date) : BOOLEAN;
  23.       FUNCTION    CurrentDate : Date;
  24.       FUNCTION    FirstDate : Date;
  25.       FUNCTION    LastDate : Date;
  26.       PROCEDURE   Advance;
  27.       END;
  28.  
  29.  
  30. IMPLEMENTATION {section}
  31.  
  32.  
  33. {============================================================================}
  34. CONSTRUCTOR DateLinkList.Init;
  35.  
  36.    {This procedure initializes the DateLinkList.}
  37.  
  38. BEGIN {DateLinkList.Init}
  39. CurrentDatePtr := NIL;
  40. LinkList.Init
  41. END; {DateLinkList.Init}
  42. {============================================================================}
  43.  
  44. {============================================================================}
  45. PROCEDURE   DateLinkList.AddDate(TheDate : Date);
  46.  
  47.    {This procedure stores TheDate in the DateLinkList.  It does nothing if
  48. TheDate already exists.}
  49.  
  50. BEGIN {DateLinkList.AddDate}
  51. IF Exists(TheDate)
  52.  THEN EXIT; {no need to hang around here, eh?}
  53.  
  54. IF ((First = NIL)
  55.  OR (FirstDate > TheDate))
  56.  THEN
  57.     Insert(NEW(DateObjectPtr,Init(TheDate)))
  58.  ELSE
  59.     BEGIN
  60.     CurrentDatePtr := DateObjectPtr(First);
  61.     WHILE ((CurrentDate < TheDate)
  62.      AND (CurrentDate <> BadDate))
  63.      DO Advance;
  64.  
  65.     {CurrentDatePtr now points to the first date coming after TheDate, or it
  66.        has a NIL value.}
  67.     IF (CurrentDate = BadDate)
  68.      THEN Append(NEW(DateObjectPtr,Init(TheDate)))
  69.      ELSE Before(NEW(DateObjectPtr,Init(TheDate)),CurrentDatePtr)
  70.     END
  71. END; {AddDate}
  72. {============================================================================}
  73.  
  74. {============================================================================}
  75. PROCEDURE   DateLinkList.DeleteDate(TheDate : Date);
  76.  
  77.    {This procedure deletes a date from the DateLinkList.  It does nothing if
  78. the Date doesn't exist.}
  79.  
  80. BEGIN {DateLinkList.DeleteDate}
  81. IF Exists(TheDate)
  82.  THEN
  83.     BEGIN
  84.     CurrentDatePtr := DateObjectPtr(First);
  85.     WHILE (CurrentDatePtr^.GetDate <> TheDate)
  86.      DO CurrentDatePtr := DateObjectPtr(CurrentDatePtr^.Next);
  87.  
  88.     {CurrentDatePtr now points to the proper date.}
  89.     Remove(CurrentDatePtr);
  90.     DISPOSE(CurrentDatePtr,Done);
  91.     CurrentDatePtr := NIL
  92.     END
  93. END; {DateLinkList.DeleteDate}
  94. {============================================================================}
  95.  
  96. {============================================================================}
  97. FUNCTION    DateLinkList.Exists(TheDate : Date) : BOOLEAN;
  98.  
  99.    {This function determines if the date is on the DateLinkList.}
  100.  
  101. VAR
  102.    TempBoolean : BOOLEAN;
  103.  
  104. BEGIN {DateLinkList.Exists}
  105. IF ((TheDate = BadDate) OR (FirstDate = BadDate))
  106.  THEN
  107.     Exists := FALSE
  108.  ELSE
  109.     BEGIN
  110.     TempBoolean := FALSE;
  111.     REPEAT
  112.         IF (CurrentDatePtr^.GetDate = TheDate)
  113.          THEN TempBoolean := TRUE;
  114.          {ELSE leave TempBoolean alone}
  115.  
  116.         CurrentDatePtr := DateObjectPtr(Next(CurrentDatePtr))
  117.      UNTIL (CurrentDatePtr = NIL);
  118.  
  119.     Exists := TempBoolean
  120.     END
  121. END; {DateLinkList.Exists}
  122. {============================================================================}
  123.  
  124. {============================================================================}
  125. FUNCTION    DateLinkList.CurrentDate : Date;
  126.  
  127.    {This function returns the current date in the DateLinkList.}
  128.  
  129. BEGIN {DateLinkList.CurrentDate}
  130. IF (CurrentDatePtr = NIL)
  131.  THEN CurrentDate := BadDate
  132.  ELSE CurrentDate := CurrentDatePtr^.GetDate
  133. END; {DateLinkList.CurrentDate}
  134. {============================================================================}
  135.  
  136. {============================================================================}
  137. FUNCTION    DateLinkList.FirstDate : Date;
  138.  
  139.    {This function simply returns the first date in the LinkList.}
  140.  
  141. BEGIN {DateLinkList.FirstDate}
  142. CurrentDatePtr := DateObjectPtr(First);
  143. IF (CurrentDatePtr = NIL)
  144.  THEN FirstDate := BadDate
  145.  ELSE FirstDate := CurrentDatePtr^.GetDate
  146. END; {DateLinkList.FirstDate}
  147. {============================================================================}
  148.  
  149. {============================================================================}
  150. FUNCTION    DateLinkList.LastDate : Date;
  151.  
  152.    {This function simply returns the last date in the LinkList.}
  153.  
  154. BEGIN {DateLinkList.LastDate}
  155. CurrentDatePtr := DateObjectPtr(Last);
  156. IF (CurrentDatePtr = NIL)
  157.  THEN LastDate := BadDate
  158.  ELSE LastDate := CurrentDatePtr^.GetDate
  159. END; {DateLinkList.LastDate}
  160. {============================================================================}
  161.  
  162. {============================================================================}
  163. PROCEDURE   DateLinkList.Advance;
  164.  
  165.    {This procedure simply moves to the next date in the DateLinkList.}
  166.  
  167. BEGIN {DateLinkList.NextDate}
  168. CurrentDatePtr := DateObjectPtr(Next(CurrentDatePtr))
  169. END; {NextDate}
  170. {============================================================================}
  171.  
  172.  
  173. END. {DateLink}
  174.